package org.jeecg.mall.carItem.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.mall.carItem.model.CartProduct;
import org.jeecg.mbg.model.OmsCartItem;
import org.jeecg.mall.carItem.model.CartPromotionItem;
import org.jeecg.mall.carItem.service.OmsCartItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 购物车管理Controller
 */
@Api(tags = "OmsCartItemController", description = "购物车管理")
@Controller
@RequestMapping("/cart")
public class OmsCartItemController {
    @Autowired
    private OmsCartItemService cartItemService;


    @ApiOperation("添加商品到购物车")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result add(@RequestBody OmsCartItem cartItem) {
        int count = cartItemService.add(cartItem);
        if (count > 0) {
            return Result.OK("",count);
        }
        return Result.error("失败");
    }

    @ApiOperation("获取某个会员的购物车列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Result<List<OmsCartItem>> list() {
//        List<OmsCartItem> cartItemList = cartItemService.list(memberService.getCurrentMember().getId());
//        return Result.OK(cartItemList);
        List<OmsCartItem> omsCartItems=new ArrayList<>();
        return Result.OK(omsCartItems);
    }

    @ApiOperation("获取某个会员的购物车列表,包括促销信息")
    @RequestMapping(value = "/list/promotion", method = RequestMethod.GET)
    @ResponseBody
    public Result<List<CartPromotionItem>> listPromotion(@RequestParam(required = false) List<Long> cartIds) {
//        List<CartPromotionItem> cartPromotionItemList = cartItemService.listPromotion(memberService.getCurrentMember().getId(), cartIds);
//        return Result.OK(cartPromotionItemList);
        List<OmsCartItem> omsCartItems=new ArrayList<>();
        return Result.OK();
    }

    @ApiOperation("修改购物车中某个商品的数量")
    @RequestMapping(value = "/update/quantity", method = RequestMethod.GET)
    @ResponseBody
    public Result updateQuantity(@RequestParam Long id,
                                       @RequestParam Integer quantity) {
//        int count = cartItemService.updateQuantity(id, memberService.getCurrentMember().getId(), quantity);
//        if (count > 0) {
//            return Result.success(count);
//        }
        return Result.error("失败");
    }

    @ApiOperation("获取购物车中某个商品的规格,用于重选规格")
    @RequestMapping(value = "/getProduct/{productId}", method = RequestMethod.GET)
    @ResponseBody
    public Result<CartProduct> getCartProduct(@PathVariable Long productId) {
//        CartProduct cartProduct = cartItemService.getCartProduct(productId);
        return Result.OK();
    }

    @ApiOperation("修改购物车中商品的规格")
    @RequestMapping(value = "/update/attr", method = RequestMethod.POST)
    @ResponseBody
    public Result updateAttr(@RequestBody OmsCartItem cartItem) {
        int count = cartItemService.updateAttr(cartItem);
        if (count > 0) {
            return Result.OK("成功",count);
        }
        return Result.error("失败");
    }

    @ApiOperation("删除购物车中的某个商品")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") List<Long> ids) {
//        int count = cartItemService.delete(memberService.getCurrentMember().getId(), ids);
//        if (count > 0) {
//            return Result.OK("成功",count);
//        }
        return Result.error("失败");
    }

    @ApiOperation("清空购物车")
    @RequestMapping(value = "/clear", method = RequestMethod.POST)
    @ResponseBody
    public Result clear() {
//        int count = cartItemService.clear(memberService.getCurrentMember().getId());
//        if (count > 0) {
//            return Result.OK("成功",count);
//        }
        return Result.error("失败");
    }
}
